package apii.servlet.stud;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import apii.server.ServerThings;
import apii.servlet.ServletUtils;
import apii.servlet.UserRequesterData;

/**
 * 
 * @author evgeniy
 * 
 */
public class StudHomeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public StudHomeServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			UserRequesterData urd = ServletUtils.extractRequesterData(request
					.getSession(false));
			if ((urd.sessionId == null) || !urd.logged
					|| (urd.role != UserRequesterData.ROLE_STUD)) {
				ServletUtils.redirectToUrl(response, "/login");
			} else {
				PrintWriter pw = response.getWriter();
				// TODO: 
				ServletUtils.startCommonStudDoc(pw, urd, "Stud home");
				pw.println("student home");
				ServletUtils.closeCommonStudDoc(pw, urd);
			}
		} catch (SQLException ex) {
			ServletUtils.redirectToErrorPage(response, ex.getMessage());
			ex.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
